package opp.Abstract.RentCar;

import java.util.Scanner;

public class Test {
    //测试类
    //2023-5-16多态技术的学习
    //两个静态方法用于传参
        static  Vickie[] vickies=new Vickie[100];
        static  int[] days =new int[100];
        static Scanner scanner=null;

        public static void main(String[] args) {

            //System.out.println("===多态案例===");
            boolean flag=true;
            int choice =0;
            String answer="";
            int day=0;
            int index=-1;//找空位置

            while (flag){
                System.out.println("==租车管理系统==\n1->卡车\n2->轿车\n3->拖拉机\n=======================\n请选择：");
                Scanner scanner=new Scanner(System.in);
                choice=scanner.nextInt();
                switch (choice) {
                    case 1:
                        System.out.println("请输入卡车载重量：");
                        int weight=scanner.nextInt();
                        System.out.println("需要租借多少天：");
                        day=scanner.nextInt();
                        index = getFeePosition();//

                        if(index!=-1){
                            vickies[index]=new Truck(weight);
                            days[index]=day;
                        }else {
                            System.out.println("剩余租车数为0");
                            flag=false;
                        }
                        break;
                    case 2:
                        System.out.println("请输入轿车载客数：");
                        int seats=scanner.nextInt();
                        System.out.println("需要租借多少天：");
                        day=scanner.nextInt();
                        index = getFeePosition();//

                        if(index!=-1){
                            vickies[index]=new Limousine(seats);
                            days[index]=day;
                        }else {
                            System.out.println("剩余租车数为0");
                            flag=false;
                        }
                        break;
                    case 3:
                        System.out.println("请输入拖拉机的排量 2T为分界线：");
                        double displacement=scanner.nextInt();
                        System.out.println("需要租借多少天：");
                        day=scanner.nextInt();
                        index = getFeePosition();//

                        if(index!=-1){
                            vickies[index]=new Tractors((int) displacement);
                            days[index]=day;
                        }else {
                            System.out.println("剩余租车数为0");
                            flag=false;
                        }
                        break;
                    default:
                        break;
                }
                if(flag){
                    System.out.println("还需要继续租车吗？ Y or N");
                    answer=scanner.next();
                    if(!answer.equalsIgnoreCase("Y")){
                        flag=false;
                    }
                }
            }
            double fee = CountTotal();
            System.out.println("需支付租金"+fee+"元");

        }

        //计算租金
        private static double CountTotal() {
            double total = 0;
            for(int i=0;i<vickies.length&&vickies[i]!=null;i++){
                total += vickies[i].CountFee(days[i]);
            }
            return total;
        }

        //获取空位置
        private static int  getFeePosition(){
            int index=-1;
            for(int i=0;i<vickies.length;i++){
                if(vickies[i]==null){
                    index=i;
                    break;
                }
            }
            return index;
        }
}



